<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<div class="x_panel">
    <div class="x_title">
        <ol class="breadcrumb pull-left">
            <li><a ng-click="navigateToPath('/origins')">Origins</a></li>
            <li class="active">{{originName}}</li>
        </ol>
        <div class="clearfix"></div>
    </div>
    <div class="x_content">
        <br>
        <form name="originForm" class="form-horizontal form-label-left" novalidate>
            <div ng-show='!settings.isNew' class="form-group">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Primary:</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="isPrimary" type="text" class="form-control" ng-value="origin.isPrimary" readonly autofocus>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.name), 'has-feedback': hasError(originForm.name)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Name *</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="name" type="text" class="form-control" ng-model="origin.name" ng-maxlength="100" ng-pattern="/^\S*$/" required autofocus>
                    <small class="input-error" ng-show="hasPropertyError(originForm.hostName, 'required')">Required</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.hostName, 'maxlength')">Too Long</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.hostName, 'pattern')">No spaces</small>
                    <span ng-show="hasError(originForm.name)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.tenantId), 'has-feedback': hasError(originForm.tenantId)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Tenant</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="tenantId" class="form-control" ng-model="origin.tenantId" ng-options="tenant.id as tenantLabel(tenant) for tenant in tenants" required>
                        <option value="">Select...</option>
                    </select>
                    <small class="input-error" ng-show="hasPropertyError(originForm.tenantId, 'required')">Required</small>
                    <small ng-show="origin.tenantId"><a href="/#!/tenants/{{origin.tenantId}}" target="_blank">View Details&nbsp;&nbsp;<i class="fa fs-xs fa-external-link"></i></a></small>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.fqdn), 'has-feedback': hasError(originForm.fqdn)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">FQDN *</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="fqdn" type="text" class="form-control" ng-model="origin.fqdn" ng-maxlength="100" ng-pattern="/^([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*$/" required autofocus>
                    <small class="input-error" ng-show="hasPropertyError(originForm.fqdn, 'required')">Required</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.fqdn, 'maxlength')">Too Long</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.fqdn, 'pattern')">Invalid</small>
                    <span ng-show="hasError(originForm.fqdn)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.ipAddress), 'has-feedback': hasError(originForm.ipAddress)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">IPv4 Address</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="ipAddress" type="text" class="form-control" ng-model="origin.ipAddress" ng-change="nullifyIfEmptyIP(origin)" ng-maxlength="15" ng-pattern="/^\d{1,3}(\.\d{1,3}){3}$/" autofocus>
                    <small class="input-error" ng-show="hasPropertyError(originForm.ipAddress, 'maxlength')">Too Long</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.ipAddress, 'pattern')">Invalid</small>
                    <span ng-show="hasError(originForm.ipAddress)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.ip6Address), 'has-feedback': hasError(originForm.ip6Address)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">IPv6 Address</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="ip6Address" type="text" class="form-control" ng-model="origin.ip6Address" ng-change="nullifyIfEmptyIP(origin)" ng-maxlength="39" ng-pattern="/^[0-9a-fA-F:]+$/" autofocus>
                    <small class="input-error" ng-show="hasPropertyError(originForm.ip6Address, 'maxlength')">Too Long</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.ip6Address, 'pattern')">Invalid</small>
                    <span ng-show="hasError(originForm.ip6Address)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.protocol), 'has-feedback': hasError(originForm.protocol)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Protocol *</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="protocol" class="form-control" ng-model="origin.protocol" ng-options="protocol.value as protocol.label for protocol in protocols" required>
                        <option value="">Select...</option>
                    </select>
                    <small class="input-error" ng-show="hasPropertyError(originForm.protocol, 'required')">Required</small>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.port), 'has-feedback': hasError(originForm.port)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">TCP Port</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <input name="port" type="number" class="form-control" ng-model="origin.port" ng-min="1" ng-max="65535" ng-pattern="/^\d+$/" autofocus>
                    <small class="input-error" ng-show="hasPropertyError(originForm.port, 'pattern')">Whole Number</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.port, 'min')">Invalid port. Must be between 1 and 65535</small>
                    <small class="input-error" ng-show="hasPropertyError(originForm.port, 'max')">Invalid port. Must be between 1 and 65535</small>
                    <span ng-show="hasError(originForm.port)" class="form-control-feedback"><i class="fa fa-times"></i></span>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.deliveryServiceId), 'has-feedback': hasError(originForm.deliveryServiceId)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Delivery Service *</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="deliveryServiceId" class="form-control" ng-model="origin.deliveryServiceId" ng-options="deliveryService.id as deliveryService.xmlId for deliveryService in deliveryServices" ng-disabled="origin.isPrimary" required>
                        <option value="">Select...</option>
                    </select>
                    <small class="input-error" ng-show="hasPropertyError(originForm.deliveryServiceId, 'required')">Required</small>
                    <small ng-show="origin.deliveryServiceId"><a ng-click="editDeliveryService(origin.deliveryServiceId)" target="_blank">View Details&nbsp;&nbsp;<i class="fa fs-xs fa-external-link"></i></a></small>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.coordinateId), 'has-feedback': hasError(originForm.coordinateId)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Coordinate</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="coordinateId" class="form-control" ng-model="origin.coordinateId" ng-options="coordinate.id as coordinate.name for coordinate in coordinates">
                        <option value="">Select...</option>
                    </select>
                    <small ng-show="origin.coordinateId"><a href="/#!/coordinates/{{origin.coordinateId}}" target="_blank">View Details&nbsp;&nbsp;<i class="fa fs-xs fa-external-link"></i></a></small>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.cachegroup), 'has-feedback': hasError(originForm.cachegroup)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Cache Group</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="cachegroup" class="form-control" ng-model="origin.cachegroupId" ng-options="cachegroup.id as cachegroup.name for cachegroup in cacheGroups">
                        <option value="">Select...</option>
                    </select>
                    <small ng-show="origin.cachegroupId"><a href="/#!/cache-groups/{{origin.cachegroupId}}" target="_blank">View Details&nbsp;&nbsp;<i class="fa fs-xs fa-external-link"></i></a></small>
                </div>
            </div>
            <div class="form-group" ng-class="{'has-error': hasError(originForm.profile), 'has-feedback': hasError(originForm.profile)}">
                <label class="control-label col-md-2 col-sm-2 col-xs-12">Profile</label>
                <div class="col-md-10 col-sm-10 col-xs-12">
                    <select name="profile" class="form-control" ng-model="origin.profileId" ng-options="profile.id as profile.name for profile in profiles">
                        <option value="">Select...</option>
                    </select>
                    <small ng-show="origin.profileId"><a href="/#!/profiles/{{origin.profileId}}" target="_blank">View Details&nbsp;&nbsp;<i class="fa fs-xs fa-external-link"></i></a></small>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" ng-show="!settings.isNew" ng-disabled="origin.isPrimary" ng-click="confirmDelete(origin)">Delete</button>
                <button type="button" class="btn btn-success" ng-disabled="originForm.$pristine || originForm.$invalid" ng-click="save(origin)">{{settings.saveLabel}}</button>
            </div>
        </form>
    </div>
</div>
